Imports Ektron.Cms.Controls
Imports System.Xml
Imports System.Xml.XPath
Imports System.Xml.Xsl
Imports System.Collections.Specialized

Partial Class menu2sitemap
    Inherits System.Web.UI.Page

    Private menuId As String = Convert.ToInt32(ConfigurationManager.AppSettings("{yoursite}menuid"))
    Private ReadOnly sitemapFileName As String = "{yoursite}web.sitemap"

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim mainMenu As Menu = New Menu()
        mainMenu.DefaultMenuID = menuId
        mainMenu.Page = Me.Page
        mainMenu.Fill()

        'Menu1.DefaultMenuID = menuId
        'Menu1.DisplayXslt = "/includes/try1.xslt" 'ConfigurationManager.AppSettings("path2SiteMapXslt").ToString()
        'Menu1.Page = Me.Page
        'Menu1.Fill()

        xml1.Document = mainMenu.XmlDoc

        Dim xm As XmlDocument = mainMenu.XmlDoc


        'xm.Save(ConfigurationManager.AppSettings("phyPath2SiteMap") & sitemapFileName)
        Dim tr As System.IO.TextReader = New System.IO.StringReader(mainMenu.XmlDoc.OuterXml)
        Dim xtw As XmlTextWriter = New XmlTextWriter(ConfigurationManager.AppSettings("phyPath2SiteMap") & sitemapFileName, Nothing)
        Dim xpDoc As XPathDocument = New XPathDocument(tr)
        Dim xsl As XslCompiledTransform = New XslCompiledTransform()
        xsl.Load(ConfigurationManager.AppSettings("{yoursite}XsltPath").ToString() & ConfigurationManager.AppSettings("siteMapXslt").ToString())
        xsl.Transform(xpDoc, Nothing, xtw)
        xtw.Close()

        litConfirmation.Text = "You Know it worked.. the {yourtitle} Sitemap file was been created successfully. <br />" & ConfigurationManager.AppSettings("phyPath2SiteMap") & sitemapFileName
    End Sub

End Class
